home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- // Copyright (C) 2000 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: December 8/2000
- // Author: jdc rendering
- //
- // Description:
- //
- // This file contains a global procedure which can be called to import an
- // image file as a file texture. Callers have some options when asking for
- // the image file to be imported, such as whether the file texture node
- // which gets created should have a placement node attached, or whether
- // the image file should be used as a projection texture.
- //
-
- global proc string importImageFile(
- string $fileName,
- int $asProjection,
- int $asStencil,
- int $withPlacement)
- {
- //
- // Description:
- // This procedure is called when some piece of UI wants to import an
- // image file to be used as a file texture.
- // This procedure creates a file texture node and potentially other nodes
- // according to the options the caller specifies, and sets the
- // fileTextureName attribute of the created file texture node to the name
- // of the file which was imported.
- //
-
- string $fileTextureNode;
-
- $fileTextureNode = renderCreateNode(
- "-as2DTexture",
- "",
- "file",
- "",
- $asProjection, // projection
- $asStencil, // stencil
- $withPlacement, // placement
- 0, // shadingGroup
- 0, // createAndDrop
- "" // editor, for createAndDrop
- );
-
- if (`nodeType $fileTextureNode` != "file")
- {
- // The result node was not a file texture, which means it was either a
- // projection or stencil node. We will look upstream to find the file
- // texture.
- //
- // ASSUMPTION:
- // We assume that the result node was either a projection or a stencil,
- // but we do not check. We also assume that the file texture we are
- // looking for is just upstream of the image attribute of the
- // projection or stencil node.
- //
- string $sources[] =
- `listConnections
- -source true
- -destination false
- -type "file"
- ($fileTextureNode + ".image")`;
- $fileTextureNode = $sources[0];
- }
-
- string $tokenArray[];
-
- tokenize($fileName, "/", $tokenArray);
-
- string $pathTail = $tokenArray[size($tokenArray) - 1];
- tokenize($pathTail, ".", $tokenArray);
- string $fileNameRoot = $tokenArray[0];
-
- if (`match "^[0-9]+" $fileNameRoot`)
- {
- // The file name begins in a number, which is invalid for the name of a
- // node in Maya, so we will prefix the name of the file texture node
- // with "file_".
- //
- // The rest of the file texture node name will be the name of the
- // file, suffixed with "_1". The effect of this naming is that if the
- // user loads the same image multiple times, the resulting file
- // texture nodes will be named with suffixes _1, _2, _3, etc.
- //
- $fileTextureNode =
- `rename $fileTextureNode ("file_" + $fileNameRoot + "_1")`;
- }
- else
- {
- // The file texture node name will be the name of the
- // file, suffixed with "_1". The effect of this naming is that if the
- // user loads the same image multiple times, the resulting file
- // texture nodes will be named with suffixes _1, _2, _3, etc.
- //
- $fileTextureNode = `rename $fileTextureNode ($fileNameRoot + "_1")`;
- }
-
- setAttr ($fileTextureNode + ".fileTextureName") -type "string" $fileName;
-
- print("// Imported: " + $fileName + "\n");
-
- return $fileTextureNode;
- }
-